#!/bin/sh

~/mount.sh

make -C ./deamon clean >> /dev/null
sudo rm -rf ./etc/Wireless/RT2870AP/wifi_deamon >> /dev/null
sudo rm -rf ./etc/Wireless/RT2870AP/*.ko >> /dev/null
make clean >> /dev/null

make all
make -C ./deamon wifi_deamon

if [ -f "./deamon/wifi_deamon" ] && [ -f "./src/os/linux/mt7601Uap.ko" ] && [ -f "./src/os/linux/rtnet7601Uap.ko" ] && [ -f "./src/os/linux/rtutil7601Uap.ko" ]; then
  sudo cp -raf ./deamon/wifi_deamon ./etc/Wireless/RT2870AP/
  sudo cp -raf ./src/os/linux/*.ko ./etc/Wireless/RT2870AP/
  sudo chown -R root:root ./etc
  sudo chmod 0755 ./etc/Wireless/RT2870AP/wifi_deamon
  sudo chmod 0755 ./etc/Wireless/RT2870AP/wifiload.sh
  sudo chmod 0644 ./etc/Wireless/RT2870AP/*.ko
  sudo chmod 0644 ./etc/Wireless/RT2870AP/*.dat
  sudo chmod 0644 ./etc/Wireless/RT2870AP/*.bak
  sudo rm -rf rt2870.tar
  tar cvf rt2870.tar etc
  sudo rm -rf rt2870.tar.xz
  xz rt2870.tar
  mv rt2870.tar.xz ~/share/tftpdir/wifi
else
  echo "~~~~~~~~~~~~~~~~failed~~~~~~~~~~~~~~~~~~~"
fi
